home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softdisk Supreme
/
Softdisk Supreme.iso
/
pc
/
DSK Files
/
0-49
/
SD010b.dsk
/
HIDDEN.LINE.3D.bas
< prev
next >
Wrap
BASIC Source File
|
2003-06-12
|
6KB
|
198 lines
5 REM <CTRL-M><CTRL-M><CTRL-M>FROM A PROGRAM BY MARK GOTTLIEB, PRINTED IN THE MAY '78 'BYTE', P 49. MODIFIED FOR APPLE II BY ALAN LACY<CTRL-J><CTRL-J>
10 TEXT : CALL -936: VTAB 4: PRINT "THIS IS A PROGRAM WHICH PLOTS 3-D FUNC- TIONS AND USES A HIDDEN LINE SUBROUTINE"
15 PRINT "A DETAILED EXPLANATION OF THIS PROGRAM IS IN THE MAY '78 'BYTE', P 49."
20 PRINT : PRINT "THE FUNCTION PLOTTED (LINE 410) CAN BE CHANGED, AS WELL AS OTHER PARAMETERS."
25 PRINT "DEPENDING ON RESOLUTION, A PLOT AVER- AGES FIFTEEN MINUTES"
30 PRINT : PRINT "HIT ANY KEY TO BEGIN THE PLOT"
40 GET D$: PRINT : PRINT : PRINT
90 LOMEM: 16384
100 HGR
110 U4 = 0:F = 1:U5 = F
120 L9 = 10
150 DIM A(1,3): DIM C(1,3)
160 DIM Q(3,3): DIM B(279,1)
165 REM PERSPECTIVE FUNCTION
170 DEF FN P(F) = D7 *F/(D7 -C(1,3))
180 REM E=STEP VALUE AND K=#STEPS
190 E = 10:K = 15
200 I = -E:I2 = E
210 REM D7=DISTANCE FROM (0,0,0) FOR PERSPECTIVE
220 D7 = 30
230 REM X2,Y2,Z2 ARE DEG. TURN AROUND X,Y&Z AXIS
240 X2 = -75:Y2 = 0:Z2 = 30
250 W = 3.1416/180: REM CONVERSION FACTOR DEGREES TO RADIANS
260 X2 = W *X2:Y2 = W *Y2:Z2 = W *Z2
290 GOSUB 6000
300 X3 = -1:Y3 = X3:X4 = X3:Y4 = X3
310 FOR H = 0 TO 279
320 B(H,1) = 159: NEXT
325 REM Y AXIS LOOP
330 FOR T = -E TO E STEP E/K
340 IF T > -.05 AND T <.05 THEN T = 0
345 REM X AXIS LOOP
350 FOR G = -E TO E STEP E/K
360 IF G > -.05 AND G <.05 THEN G = O
370 U9 = G
380 R = SQR(G *G +T *T)
390 A(1,1) = G
400 A(1,2) = T
405 REM ACTUAL FUNCTION
410 A(1,3) = 8/(R +1) * COS(R *1.2)
415 REM MATRIX MULTIPLICATION SUBROUTINE
420 FOR L = 1 TO 3
421 FOR J = 1 TO 1
422 C(J,L) = 0
423 FOR M = 1 TO 3
424 C(J,L) = C(J,L) +A(J,M) *Q(M,L)
425 NEXT : NEXT : NEXT
429 REM SCALING, PERSPECTIVE, & OFFSET
430 X = FN P(C(1,1) *100/E) +140
440 Y = -1 *( FN P(C(1,2) *100/E) -80)
445 REM GOSUB HIDDEN LINE SUBROUTINE
450 GOSUB 5000
460 NEXT : NEXT
470 PRINT "END OF PLOT": PRINT "<CTRL-G><CTRL-G><CTRL-G>"
480 END
4085 REM <CTRL-M><CTRL-M><CTRL-M>VARIABLES USED IN HIDDEN LINE SUBROUTINE:<CTRL-M>U1-U9,S7-S9,X1,Y1-X9,Y9. U8=0 (LAST IN),U8=1 (LAST OUT)<CTRL-J>
4090 REM <CTRL-M><CTRL-M>VARIABLES SET AT BEGINNING OF PROGRAM:<CTRL-M>SET I=1ST X & I2=LAST X<CTRL-M>U4=0,F=U5=1,X4=Y4=X3=Y3=-1<CTRL-J>
4095 REM <CTRL-M><CTRL-M>U9=VALUE OF X STEP<CTRL-J>
4097 REM <CTRL-M><CTRL-M>L9=MAX LENGTH OF LINE<CTRL-J>
4099 REM <CTRL-M><CTRL-M><CTRL-M>*** HIDDEN LINE SUBROUTINE ***<CTRL-J>
5000 IF X >279 OR X <0 THEN U4 = 1
5005 IF X >279 OR X <0 THEN RETURN
5010 IF U9 = I AND Y >B(X,1) AND Y <B(X,0) THEN 5140
5015 IF U9 = I OR U4 THEN GOSUB 5600
5020 IF U9 = I2 THEN GOSUB 5700
5025 U3 = 0
5030 IF U9 = I OR U4 THEN 5155
5033 IF X -X9 = 0 THEN 5125
5034 REM STEPS 5035-5085 DIVIDE LINES INTO LINES OF LENGTH L9
5035 L8 = SQR((X -X9) ^2 +(Y9 -Y) ^2)
5040 IF L8 < = L9 THEN 5090
5045 L2 = X9:L5 = X:L6 = Y:S6 = (Y9 -Y)/(X -X9)
5050 L7 = (X -X9)/(L9/L8):L4 = Y9 -S6 *X9
5060 FOR X = L2 TO L5 -L7 STEP L7
5065 Y = S6 *X +L4
5070 GOSUB 5090
5075 NEXT
5080 X = L5:Y = L6
5090 IF X -X9 = 0 THEN 5145
5099 U3 = 0
5100 S9 = (Y9 -Y)/(X -X9)
5105 IF U8 = 0 THEN 5400
5110 IF Y >B(X,1) AND Y <B(X,0) THEN 5205
5115 U8 = 1
5120 IF U9 = 1 THEN 5155
5125 GOSUB 8200
5130 GOSUB 5500
5135 GOTO 5145
5140 U8 = 0
5145 X9 = X:Y9 = Y
5150 RETURN
5151 REM RETURN TO MAIN PROGRAM
5155 X9 = X:Y9 = Y
5160 GOSUB 8100
5165 GOSUB 8200
5170 U4 = 0
5175 U8 = 1
5180 RETURN
5181 REM RETURN TO MAIN PROGRAM
5200 REM *** FIND INTERSECT ***
5205 S7 = X -X9:U2 = 0:X1 = X9:U1 = 1
5210 IF U1 >32 THEN 5285
5215 U1 = U1 *2
5220 IF U2 = 1 THEN 5235
5225 X1 = X1 +S7/U1
5230 GOTO 5240
5235 X1 = X1 -S7/U1
5240 Y7 = ABS(S9 *(X1 -X9) -Y9)
5245 IF U3 = 1 THEN 5456
5250 IF Y9 <B(X9,0) THEN 5270
5255 IF Y7 <B(X1,0) THEN U2 = 1
5260 IF Y7 >B(X1,0) THEN U2 = 0
5265 GOTO 5280
5270 IF Y7 >B(X1,1) THEN U2 = 1
5275 IF Y7 <B(X1,1) THEN U2 = 0
5280 GOTO 5210
5285 X5 = X:Y5 = Y
5290 X = X1:Y = Y7
5295 IF U3 = 1 THEN 5425
5300 U8 = 0
5305 GOSUB 8200
5310 GOSUB 5500
5315 X9 = X5:Y9 = Y5
5320 RETURN
5321 REM RETURN TO MAIN PROGRAM
5400 REM ** TEST U8=0 **
5405 IF Y <B(X,0) AND Y >B(X,1) THEN 5145
5410 U8 = 1:U3 = 1
5415 X8 = X:Y8 = Y
5420 GOTO 5205
5425 GOSUB 8100
5430 GOSUB 8200
5435 X = X8:Y = Y8:U8 = 1
5440 GOTO 5145
5450 GOTO 5145
5454 REM PART OF THE INTERSECTION ROUTINE
5455 REM ** FOR U3=1:COMING OUT **
5456 IF Y <B(X,1) THEN 5460
5457 IF Y7 >B(X1,0) THEN U2 = 1
5458 IF Y7 <B(X1,0) THEN U2 = 0
5459 GOTO 5280
5460 IF Y7 <B(X1,1) THEN U2 = 1
5465 IF Y7 >B(X1,1) THEN U2 = 0
5470 GOTO 5280
5500 REM ** FILL IN POINTS **
5505 U6 = SGN(X -X9)
5510 IF U6 = 0 THEN RETURN
5515 FOR U7 = X9 TO X STEP U6
5520 S8 = Y9 +S9 *(U7 -X9)
5522 IF S8 >B(U7,0) THEN B(U7,0) = S8
5524 IF S8 <B(U7,1) THEN B(U7,1) = S8
5530 NEXT
5535 RETURN
5600 REM ** FILL IN LEFT SIDE **
5610 IF X4 < > -1 THEN 5640
5620 X4 = X:Y4 = Y
5630 RETURN
5640 X8 = X9:Y8 = Y9
5650 X9 = X4:Y9 = Y4
5660 S9 = (Y9 -Y)/(X -X9)
5670 GOSUB 5500
5680 X9 = X8:Y9 = Y8
5690 GOTO 5620
5700 REM ** FILL IN RIGHT SIDE **
5710 IF X3 < > -1 THEN 5740
5720 X3 = X:Y3 = Y
5730 RETURN
5740 X8 = X9:Y8 = Y9
5750 X9 = X3:Y9 = Y3
5760 S9 = (Y9 -Y)/(X -X9)
5770 GOSUB 5500
5780 X9 = X8:Y9 = Y8
5790 GOTO 5720
6000 REM MAT ROTATE
6001 REM 6020-6110 MAKES MATRIX
6002 REM Q THE FINAL ROTATIONAL
6003 REM MATRIX
6020 Q(1,1) = COS(Z2) * COS(Y2)
6030 Q(2,1) = -1 * SIN(Z2) * COS(Y2)
6040 Q(3,1) = -1 * SIN(Y2)
6050 Q(1,2) = COS(Z2) *( -1) * SIN(X2) * SIN(Y2) + SIN(Z2) * COS(X2)
6060 Q(2,2) = SIN(Z2) * SIN(X2) * SIN(Y2) + COS(Z2) * COS(X2)
6070 Q(3,2) = -1 * SIN(X2) * COS(Y2)
6080 Q(1,3) = COS(Z2) * COS(X2) * SIN(Y2) + SIN(Z2) * SIN(X2)
6090 Q(2,3) = -1 * SIN(Z2) * COS(X2) * SIN(Y2) + COS(Z2) * SIN(X2)
6100 Q(3,3) = COS(X2) * COS(Y2)
6110 RETURN
8099 REM 'INVISIBLE VECTOR' SUBROUTINE
8100 A = 1: RETURN
8199 REM VISIBLE VECTOR SUBROUTINE
8200 HCOLOR= 7
8205 IF X >279 THEN X = 279
8206 IF X <0 THEN X = 0
8207 IF Y >159 THEN Y = 159
8208 IF Y <0 THEN Y = 0
8217 IF A = 1 GOTO 8230
8220 HPLOT TO X,Y: RETURN
8230 HPLOT X,Y:A = 0: RETURN